package com.acme.domain.account;

import com.acme.exceptions.NoEnoughFundsException;

public class SavingAccount extends AbstractAccount {

	public SavingAccount(final int id, final double amount) {
		super(id, amount);
	}

	@Override
	public void deposit(final double amount) throws IllegalArgumentException {
		if (amount < 0) {
			throw new IllegalArgumentException("Amount can not be negative");
		}
		this.balance += amount;
	}

	@Override
	public void withdraw(final double amount) throws NoEnoughFundsException {
		if (amount < 0) {
			throw new IllegalArgumentException("Amount can not be negative");
		}
		if (this.balance - amount >= 0) {
			this.balance -= amount;
		} else {
			throw new NoEnoughFundsException(amount);
		}

	}

	public AccountType getAccountType() {
		return AccountType.SAVING;
	}

	public String toString() {
		String clientStr = "\n\tbalance: ";
		String clientInfo = clientStr + getBalance();
		return clientInfo;

	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		long temp;
		temp = Double.doubleToLongBits(balance);
		result = prime * result + (int) (temp ^ (temp >>> 32));
		return result;
	}

	public boolean equals(Object obj) {
		SavingAccount clientAcc;
		if (this == obj) {
			return true;
		}
		if (this == null) {
			return false;
		}
		if (!(obj instanceof SavingAccount)) {
			clientAcc = (SavingAccount) obj;
		} else {
			return false;
		}
		if (this.balance != clientAcc.getBalance()) {
			return false;
		}
		return true;
	}

}
